package com.example.cfm.shakespearean;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by cfm on 16-2-3.
 */
public class DetailsFragment extends Fragment{
    public static final String TAG = "DetailsFragment";

    private int mIndex = 0;

    public static DetailsFragment newInstance(int index){
        Log.v(TAG, "in DetailsFragment new Instance ( " +
        index + ")");
        DetailsFragment df = new DetailsFragment();
        // Supply index input as an argument.
        Bundle args = new Bundle();
        args.putInt("index", index);
        df.setArguments(args);
        return df;
    }

    public static DetailsFragment newInstance(Bundle bundle){
        int index = bundle.getInt("index", 0);
        return newInstance(index);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.v(MainActivity.TAG, "in DetailsFragment onCreate. Bundle contains:");
        if (savedInstanceState != null){
            for (String key:savedInstanceState.keySet()){
                Log.v(MainActivity.TAG, "    " + key);
            }
        }
        else {
            Log.v(MainActivity.TAG, "  savedInstanceState is null");
        }
        super.onCreate(savedInstanceState);

        mIndex = getArguments().getInt("index", 0);
    }

    public int getShownIndex() {
        return mIndex;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.v(MainActivity.TAG, "in DetailFragment onCreateView.container = " + container);
        // Don't tie this fragment to anything through the inflater.
        // Android takes care of attaching fragments for us. the container is only
        // passed in so you can know about the
        // container where this View hierarychy is going to go.
        View v = inflater.inflate(R.layout.details, container, false);
        TextView text1 = (TextView)v.findViewById(R.id.text1);
        text1.setText(Shakespeare.DIALOGUE[mIndex]);
        return super.onCreateView(inflater, container, savedInstanceState);
    }


}
